<template>
  <div class="scekill_activity_container">
    <div class="top_box">
      <a-card style="width: 100%">
        <div>
          <div class="filter_search">
            <div>
              <div class="filter_search">
                <div>
                  <a-icon type="search" />
                  筛选搜索
                </div>
              </div>
            </div>
            <div class="btnbox">
              <a-button class="btnLeft"> 重置 </a-button>
              <a-button type="primary"> 查询搜索 </a-button>
            </div>
          </div>
          <div class="activity_box">
            活动名称：<a-input placeholder="活动名称" style="width: 200px" />
          </div>
        </div>
      </a-card>
    </div>
    <div class="data_box">
      <a-card style="width: 100%">
        <div class="data_list">
          <div>
            <a-icon type="container" />
            数据列表
          </div>
          <div class="btnbox">
            <a-button size="small" class="btnLeft" @click="$router.push('/seckillTime')">
              秒杀时间段列表
            </a-button>
            <a-button size="small" @click="visible = true">
              参加活动
            </a-button>
          </div>
        </div>
      </a-card>
    </div>
    <div class="data_table">
      <a-table :columns="columns" :data-source="data" bordered :row-selection="rowSelection" :pagination="pagination">
        <span slot="id" slot-scope="id">{{ id }}</span>
        <span slot="activity_title" slot-scope="activity_title">{{ activity_title }}</span>
        <span slot="activity_state" slot-scope="activity_state">{{ activity_state === 0 ? '未开始' : '进行中' }}</span>
        <span slot="startTime" slot-scope="startTime">{{ startTime }}</span>
        <span slot="endTime" slot-scope="endTime">{{ endTime }}</span>
        <span slot="online" slot-scope="online"><a-switch :checked="!!online" @change="onChange" /></span>
        <span slot="action">
          <a-button type="link" size="small"> 设置商品 </a-button>
          <a-button type="link" size="small"> 编辑 </a-button>
          <a-button type="link" size="small"> 删除 </a-button>
        </span>
      </a-table>
    </div>
    <div class="addActivity_box">
      <a-modal
        title="添加活动"
        :visible="visible"
        :confirm-loading="confirmLoading"
        ok-text="确认"
        cancel-text="取消"
        @ok="handleOk"
        @cancel="handleCancel"
      >
        <div>
          <a-form :form="form">
            <a-form-item
              :label-col="formItemLayout.labelCol"
              :wrapper-col="formItemLayout.wrapperCol"
              label="活动名称"
            >
              <a-input
                placeholder="请输入活动名称"
              />
            </a-form-item>
            <a-form-item label="开始时间" :label-col="formTailLayout.labelCol">
              <a-time-picker v-decorator="['time-picker', config]" placeholder="选择开始时间" />
            </a-form-item>
            <a-form-item label="结束时间" :label-col="formTailLayout.labelCol">
              <a-time-picker v-decorator="['time-picker', config]" placeholder="选择结束时间" />
            </a-form-item>
            <a-form-item label="上线/下线" :label-col="formTailLayout.labelCol">
              <div class="radio_box">
                <a-radio-group v-model="value" @change="onChangeRadio">
                  <a-radio :value="1">
                    上线
                  </a-radio>
                  <a-radio :value="0">
                    下线
                  </a-radio>
                </a-radio-group>
              </div>
            </a-form-item>
          </a-form>
        </div>
      </a-modal>
    </div>
  </div>
</template>

<script>
const columns = [
  {
    title: '编号',
    dataIndex: 'id',
    width: '10%',
    scopedSlots: { customRender: 'id' },
    align: 'center'
  },
  {
    title: '活动标题',
    dataIndex: 'activity_title',
    width: '15%',
    scopedSlots: { customRender: 'activity_title' },
    align: 'center'
  },
  {
    title: '活动状态',
    dataIndex: 'activity_state',
    width: '10%',
    scopedSlots: { customRender: 'activity_state' },
    align: 'center'
  },
  {
    title: '开始时间',
    dataIndex: 'startTime',
    scopedSlots: { customRender: 'startTime' },
    align: 'center'
  },
  {
    title: '结束时间',
    dataIndex: 'endTime',
    scopedSlots: { customRender: 'endTime' },
    align: 'center'
  },
  {
    title: '上线/下线',
    dataIndex: 'online',
    scopedSlots: { customRender: 'online' },
    align: 'center'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '20%',
    scopedSlots: { customRender: 'action' },
    align: 'center'
  }
]
const pagination = {
  pageSize: 5
}
const formItemLayout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 10 }
}
const formTailLayout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 14, offset: 4 }
}
import { getSeckillList } from '@/api/marketing'
export default {
  data() {
    return {
      data: [],
      columns,
      pagination,
      visible: false,
      confirmLoading: false,
      formItemLayout,
      formTailLayout,
      form: this.$form.createForm(this, { name: 'addActivity' }),
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      config: {
        rules: [{ type: 'object', required: true, message: 'Please select time!' }]
      },
      value: 1
    }
  },
  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          console.log(
            `selectedRowKeys: ${selectedRowKeys}`,
            'selectedRows: ',
            selectedRows
          )
        },
        getCheckboxProps: (record) => ({
          props: {
            disabled: record.name === 'Disabled User', // Column configuration not to be checked
            name: record.name
          }
        })
      }
    }
  },
  created() {
    this.getSeckillList()
  },
  methods: {
    onChange(checked) {
      console.log(`a-switch to ${checked}`)
    },
    async getSeckillList() {
      const { seckill_actibity_item: res } = await getSeckillList()
      this.data = res
    },
    onChangeRadio(e) {
      console.log('radio checked', e.target.value)
    },
    handleOk(e) {
      this.ModalText = 'The modal will be closed after two seconds'
      this.confirmLoading = true
      setTimeout(() => {
        this.visible = false
        this.confirmLoading = false
      }, 500)
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible = false
    },
    check() {
      this.form.validateFields(err => {
        if (!err) {
          console.info('success')
        }
      })
    }
  }
}
</script>

<style lang="scss">
.scekill_activity_container {
  margin: 20px;

  .top_box,
  .data_box {
    margin-bottom: 20px;
  }

  .filter_search {
    display: flex;
    justify-content: space-between;
  }

  .btnLeft {
    margin-right: 10px;
  }

  .data_list {
    display: flex;
    justify-content: space-between;
  }
  .activity_box {
    margin-left: 20px;
    margin-bottom: 20px;
  }
}
</style>
